package 刷题10月.leecodehot100;
import java.util.*;


public class Solution2 {

    public String compress (String inputvalue) {
        // write code here
        if(inputvalue.length()<2){
            return inputvalue;
        }
        int left=0;
        int right=1;
        StringBuffer stringBuffer=new StringBuffer();
        while(right<=inputvalue.length()-1){
            if(inputvalue.charAt(left)!=inputvalue.charAt(right)){
                stringBuffer.append(inputvalue.charAt(left));
                stringBuffer.append(right-left);
                left=right;
                right++;
            }
            else {
                right++;
            }
        }
        stringBuffer.append(inputvalue.charAt(left));
        stringBuffer.append(right-left);
        if(stringBuffer.length()<inputvalue.length()){
            return stringBuffer.toString();
        }
        else {
            return inputvalue;
        }
    }
}